package com.wcbdota.ui;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.text.Html;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.wcbdota.R;
import com.wcbdota.base.BaseUi;
import com.wcbdota.base.C;
import com.wcbdota.model.Items;
import com.wcbdota.util.AppUtil;
import com.wcbdota.util.DataCheck;
import com.wcbdota.util.SDUtil;
import com.wcbdota.util.UIUtil;

public class UiItemContent extends BaseUi{
	
	private TextView tv_itemname,tv_price,tv_desc,tv_summary,tv_effect,tv_value,pt_tv_titlename;
	ImageView img_iname,img_gold,mIv_Title;
	Button btn_back;
	String ef="";
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.item_content_layout);
		getView();
		useView();
		
	}
	@Override
	public void onStart() {
		super.onStart();
		//useView();
	}
	private void getView(){
		tv_itemname=(TextView)findViewById(R.id.tv_itemname);
		tv_price =(TextView)findViewById(R.id.tv_price);
		tv_desc=(TextView)findViewById(R.id.tv_desc);
		tv_summary=(TextView)findViewById(R.id.tv_summary);
		tv_effect=(TextView)findViewById(R.id.tv_effect);
		tv_value=(TextView)findViewById(R.id.tv_value);
		img_iname=(ImageView)findViewById(R.id.img_iname);
		img_gold=(ImageView)findViewById(R.id.gold);
		findViewById(R.id.pt_bt_back).setOnClickListener(new ButtonListener());
		findViewById(R.id.pt_bt_reload).setOnClickListener(new ButtonListener());
		pt_tv_titlename = (TextView) findViewById(R.id.pt_tv_titlename);
		
	}
	
	private void useView(){
		Items getItem =(Items)getIntent().getSerializableExtra("item");
		System.out.println("this is a item"+getItem);
		tv_itemname.setText(getItem.getName().toString());
		tv_price.setText(getItem.getPrice().toString());
		tv_desc.setText(DataCheck.getData(getItem.getDesc().toString()));
		tv_summary.setText(getItem.getSummary().toString());
		
		String [] effects =getItem.getEffectarray().split(",");
		
		for(int i=0;i<effects.length;i++){
			ef+="<font color=\"#008acf\">"+effects[i]+"</font><br>";
		}
		
		tv_effect.setText(Html.fromHtml(ef));
		tv_value.setText(DataCheck.toChangeLine(getItem.getValuearray().toString()));
		String iurl = C.remoteres.base + C.remoteres.items + "/" + getItem.getImg() + ".png";
		String cashKey =AppUtil.md5(iurl);
		Bitmap bitmap =SDUtil.getImage(cashKey);
		img_iname.setImageBitmap(bitmap);
		pt_tv_titlename.setText("装备详情");
	}
	
	class ButtonListener implements OnClickListener{
		@Override
		public void onClick(View v) {
			switch(v.getId()){
				case R.id.pt_bt_back:
					finish();
				break;
				case R.id.pt_bt_reload:
					Toast.makeText(UiItemContent.this, "已是最新数据 :) ", Toast.LENGTH_SHORT).show();
				break;
			}
		}
	}
}
